package com.lys.emsystem.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lys.emsystem.entity.Area;
import com.lys.emsystem.service.IAreaService;
import com.lys.emsystem.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author liyansheng
 * @since 2022-05-02
 */
@RestController
@CrossOrigin
@RequestMapping("/area")
public class AreaController {

    @Autowired
    private IAreaService iAreaService;

    @GetMapping
    public Result findProvince() {
        QueryWrapper<Area> wrapper = new QueryWrapper<>();
        wrapper.eq("level", 1);
        List<Area> list = iAreaService.list(wrapper);
        return Result.buildResult(Result.Status.OK, list);
    }

    @PostMapping("/{pid}")
    public Result findUrban(@PathVariable("pid") String pid) {
        QueryWrapper<Area> wrapper = new QueryWrapper<>();
        wrapper.eq("level", 2);
        wrapper.eq("pid", pid);
        List<Area> list = iAreaService.list(wrapper);
        return Result.buildResult(Result.Status.OK, list);
    }

    @PostMapping("/urban/{pid}")
    public Result findTown(@PathVariable("pid") String pid) {
        QueryWrapper<Area> wrapper = new QueryWrapper<>();
        wrapper.eq("level", 3);
        wrapper.eq("pid", pid);
        List<Area> list = iAreaService.list(wrapper);
        return Result.buildResult(Result.Status.OK, list);
    }
}
